// Copyright (c) 2014 Morten Bakkedal
// This code is published under the MIT License.

using System;
using System.Collections.Generic;

using FuncLib.DualFunctions.Collections.Generic;
using FuncLib.Functions;

namespace FuncLib.DualFunctions.Collections
{
	[Serializable]
	public class Hessian : ReadOnlyDictionary<HessianEntry, double>
	{
		public Hessian()
			: this(new Dictionary<HessianEntry, double>())
		{
		}

		public Hessian(IDictionary<HessianEntry, double> hessian)
			: base(new Dictionary<HessianEntry, double>(hessian))
		{
		}

		public bool Contains(Variable variable1, Variable variable2)
		{
			// Probably the fastest way to do this. This is O(1).
			return ContainsKey(new HessianEntry(variable1, variable2));
		}

		public double this[Variable variable1, Variable variable2]
		{
			get
			{
				return this[new HessianEntry(variable1, variable2)];
			}
		}
	}
}
